package br.com.hectordufau.rpgiiidetmobile;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.com.hectordufau.rpgiiidetmobile.Personagem;

public class PersonagemAdapter extends BaseAdapter {

	private final List<Personagem> rows;

	public PersonagemAdapter(final Context context, final int itemResId, final List<Personagem> items) 
	{
		this.rows = items;
	}

	public int getCount() 
	{
		return this.rows.size();
	}

	public Object getItem(int position) 
	{
		return this.rows.get(position);
	}

	public long getItemId(int position) 
	{
		return position;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		final Personagem row = this.rows.get(position);
		View itemView = null;		
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) parent.getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			itemView = inflater.inflate(R.layout.telaprincipal, null);
		} else {
			itemView = convertView;
		}
		TextView txtId = (TextView) itemView.findViewById(R.id.rowId);
		txtId.setText(row.getId());		
		TextView txtDesc = (TextView) itemView.findViewById(R.id.rowNome);
		txtDesc.setText(row.getNome());	
		
		return itemView;
	}

	public void deleteRow(Personagem row) 
	{		
		if(this.rows.contains(row)) 
		{
			this.rows.remove(row);
		}
	}
}